<template>
	<div>
		<AplidForm
			ref="taskInfo"
			v-model="taskInfoData"
			labelWidth="100"
			labelPostion="left"
			:show-btn="showBtn"
			:column="taskInfoConfig"
			@submit="onSubmit"
		></AplidForm>
	</div>
</template>

<script setup lang="ts">
import AplidForm from '@/components/AplidCrud/src/AplidForm/index.vue'
import {uploadType} from '@/utils/util'
import apiMod from '@/apiMod/index'

let emits = defineEmits(['refresh','onSubmit'])

let props = defineProps({
	nowRowData: {
		type: Object,
		default: () => ({}),
	},
	showBtn: {
		type: Boolean,
		default: false,
	},
})


let activeIndex = ref(1)
let taskInfoData:any = ref({})
if(props.nowRowData){
  taskInfoData.value = props.nowRowData
}
let taskInfoConfig = ref([
	{
		label: '总任务名称',
		type: 'input',
		prop: 'taskName',
		span: 24,
	},
	{
		label: '描述',
		type: 'input',
		prop: 'taskIntro',
		span: 24,
	},
	{
		label: '开始时间',
		type: 'date',
		format: 'YYYY年MM月DD',
		valueFormat: 'YYYY-MM-DD',
		prop: 'startTime',
		span: 24,
		rules:[{required:true,message:"请选择开始时间"}]
	},
	{
		label: '结束时间',
		type: 'date',
		format: 'YYYY年MM月DD',
		valueFormat: 'YYYY-MM-DD',
		prop: 'endTime',
		span: 24,
		rules:[{required:true,message:"请选择结束时间"}]
	},
	{
		label: '紧急程度',
		type: 'select',
		defaultValue: '0',
		prop: 'emergencyDegree',
		propName: 'emergencyDegreeLabel',
		dicData: [
			{ label: '普通', value: '0' },
			{ label: '紧急', value: '1' },
		],
		span: 24,
	},
	{
		label: '备注',
		type: 'textarea',
		prop: 'remark',
		span: 24,
	},
	{
		label: '附件',
		type: 'upload',
		fileType: uploadType.fileMetaType,
		listType: 'text',
		labelPosition: 'top',
		showFileList: true,
		limit: 1,
		multiple: true,
		prop: 'taskAttachment',
		span: 24,
	},
])
let taskInfo = ref()

const submit = () => {
	if(taskInfoData.value.emergencyDegree==0){
		taskInfoData.value.emergencyDegreeLabel='普通'
	}
	// if(!taskInfoData.value.startTime||!taskInfoData.value.endTime){
	// 	return
	// }
	taskInfo.value.onSubmit().then(res=>{
		if(res){
			emits('onSubmit', taskInfoData.value)
		}
	})

}

const onSubmit = (form, done) => {
	if(form.id){
		apiMod.view_zwglTaskInfo_edit(form).then(res=>{
    ElMessage.success('编辑成功')
    emits('refresh')
    done()
  }).catch(err=>{
    done()
  })
	}
	// 处理一下编辑
}
defineExpose({
	submit,
})
</script>
<style scoped lang="scss">
.btn_part {
	margin: 0 auto;
	width: 40%;
	display: flex;
	flex-direction: row;
	justify-content: space-around;
	align-items: center;
}
</style>
